/**
 * Project Name:ecsmts_mina
 * File Name:KeepAliveMessageFactoryImpl.java
 * Package Name:com.aliyun.server.heartbeat
 * Date:2013-7-22下午1:45:05
 * Copyright (c) 2013, 13940488705@163.com All Rights Reserved.
 *
 */

package com.aliyun.server.heartbeat;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.keepalive.KeepAliveMessageFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * ClassName:KeepAliveMessageFactoryImpl <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON. <br/>
 * Date: 2013-7-22 下午1:45:05 <br/>
 * 
 * @author zhangfeng
 * @version
 * @since JDK 1.6
 * @see
 */
public class KeepAliveMessageFactoryImpl implements KeepAliveMessageFactory {

	private static final Logger LOG = LoggerFactory
			.getLogger(KeepAliveMessageFactoryImpl.class);

	/** 心跳包内容 */
	private static final String HEARTBEATREQUEST = "HEARTBEATREQUEST";
	private static final String HEARTBEATRESPONSE = "HEARTBEATRESPONSE";

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.mina.filter.keepalive.KeepAliveMessageFactory#getRequest
	 * (org.apache.mina.core.session.IoSession)
	 */
	@Override
	public Object getRequest(IoSession session) {
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.mina.filter.keepalive.KeepAliveMessageFactory#getResponse
	 * (org.apache.mina.core.session.IoSession, java.lang.Object)
	 */
	@Override
	public Object getResponse(IoSession session, Object request) {
		LOG.info("返回预设语句" + HEARTBEATRESPONSE);
		/** 返回预设语句 */
		return HEARTBEATRESPONSE;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.mina.filter.keepalive.KeepAliveMessageFactory#isRequest
	 * (org.apache.mina.core.session.IoSession, java.lang.Object)
	 */
	@Override
	public boolean isRequest(IoSession session, Object message) {
		LOG.info("是否是心跳包: " + message);
		if (message.equals(HEARTBEATREQUEST))
			return true;
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.mina.filter.keepalive.KeepAliveMessageFactory#isResponse
	 * (org.apache.mina.core.session.IoSession, java.lang.Object)
	 */
	@Override
	public boolean isResponse(IoSession session, Object message) {
		LOG.info("是否是心跳包: " + message);
		if (message.equals(HEARTBEATRESPONSE))
			return true;
		return false;
	}

}
